const query = require('../../config/query');
const queryService = async (ctx, next) => {
    console.log(ctx);
    let res = await query(` SELECT * FROM user `);
    console.log(res);
    return res;
}
// 删除
const deldeteService=async(ctx,next)=>{
    const {id}=ctx.params
    let res = await query(` DELETE FROM user
    WHERE id='${id}' `);
    console.log(res);
    return res;
}
// 改
const updateService=async(ctx,next)=>{
    const { username, password, nickname, age, phone } = ctx.request.body
    const {id}=ctx.params
    let res = await query(` UPDATE user 
    SET username='${username}',password='${password}',nickname='${nickname}',age=${age},phone='${phone}' 
    WHERE id='${id}' `);
    console.log(res);
    return res;
}
// 添加
const addToService = async (ctx, next) => {
    const { username, password, nickname, age, phone } = ctx.request.body
    let res = await query(` INSERT INTO user (username,password,nickname,age,phone)
    VALUES ('${username}','${password}','${nickname}',${age},'${phone}') `);
    console.log(res);
    return res;
}
module.exports = {
    queryService,
    addToService,
    deldeteService,
    updateService
}